You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

28 lines
940 B

import { z } from "zod";
import { validate } from "#server/utils/validation";
import { updateProject, getProject } from "../../service/projects";
const updateSchema = z.object({
name: z.string().min(1, "项目名不能为空").max(100).optional(),
tags: z.string().max(500).nullable().optional(),
description: z.string().max(1000).nullable().optional(),
path: z.string().max(500).nullable().optional(),
});
export default defineWrappedResponseHandler(async (event) => {
const id = parseInt(getRouterParam(event, "id") || "");
if (!id || isNaN(id)) {
throw createError({ statusCode: 400, statusMessage: "无效的项目 ID" });
}
const existing = await getProject(id);
if (!existing) {
throw createError({ statusCode: 404, statusMessage: "项目不存在" });
}
const body = await readBody(event);
const data = validate(updateSchema, body);
await updateProject(id, data);
return R.success(null);
});